#include "comm.hpp"

int main()
{
    key_t key = getKey();
    printf("key = 0x%x\n", key);
    int shmid = createShm(key);
    printf("shmid = %d\n", shmid);
    char *start = (char *)attachShm(shmid);
    printf("attach success, address start: %p\n", start);
    int cnt = 0;
    while (true)
    {
        printf("client say: %s\n", start);
        struct shmid_ds ds;
        shmctl(shmid, IPC_STAT, &ds);
        printf("获取属性: size: %d, pid: %d, myself: %d, key: 0x%x\n",
               ds.shm_segsz, ds.shm_cpid, getpid(), ds.shm_perm.__key);
        sleep(1);
        cnt++;
        if (cnt == 10)
        {
            break;
        }
    }

    detachShm(start);
    delShm(shmid);
    std::cout << "delete shm success." << std::endl;
    return 0;
}